Add bounds check on AES-CTS input length to prevent integer overflow#422
Merged
padelsbach merged 1 commit intoJul 1, 2026
Merged
Conversation
The CTS encrypt/decrypt helpers cast the block count to int, so an inLen above 0x7FFFFFFF overflows blocks*AES_BLOCK_SIZE and smashes the stack copy. Not reachable via EVP_CipherUpdate (its inl is int); guard added as defense in depth for a caller driving OSSL_FUNC_cipher_update directly.
padelsbach
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AES-CTS encrypt/decrypt helpers in
wp_aes_stream.ccompute the block count as a signedint, so aninLenabove0x7FFFFFFFoverflowsblocks * AES_BLOCK_SIZE. The corrupted (negative) value then explodesinLenviainLen -= blocks * AES_BLOCK_SIZE, leading to an out-of-boundsXMEMCPYinto the 32-bytectsBlockstack buffer.Adds an upper-bound guard in
wp_aes_stream_doit(next to the existing lower-bound check) covering both the encrypt and decrypt paths.Not reachable through
EVP_CipherUpdate(itsinlisint, so input is already capped atINT_MAX); the guard is defense in depth for a caller drivingOSSL_FUNC_cipher_updatedirectly. No new test — triggering would require a >2 GB input that the EVP API can't pass; existing CTS KAT/KRB/error-case tests pass unchanged.Fixes Fenrir F-4380 and F-4381